package com.ruoyi.web.controller.personnel;

import com.ruoyi.personnel.domain.Employee;
import com.ruoyi.personnel.service.LikeService;
import com.ruoyi.personnel.service.impl.EmployeeServiceImpl;
import com.ruoyi.personnel.utils.DynamicInfo;
import com.ruoyi.personnel.utils.PhoneInfo;
import com.ruoyi.web.controller.email.RabbitMQConfig;
import com.ruoyi.web.controller.email.EmailSong;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author : 张培浩
 * @date : 2023/3/8 17:12
 **/

@RestController
@RequestMapping("/personnel/like")
public class LikeController {
    @Autowired
    private EmployeeServiceImpl employeeService;
    @Autowired
    private LikeService likeService;


    @Autowired
    private RabbitTemplate rabbitTemplate;


    /**
     * 获取展示信息
     * @return
     */
    @PreAuthorize("@ss.hasPermi('personnel:like:list')")
    @GetMapping("/list")
    public List<Employee> getLikeEmp(){
        // 获取员工信息
        List<Employee> employeeList = employeeService.selectEmployeeList(null);
        for (Employee employee : employeeList) {
            // 获取当前排名
            int isRank =  likeService.getRanking(employee.getEmpId()) + 1;
            employee.setRanking(isRank == 0 ? "未收到点赞信息" : "当前排名:" +isRank+"名");
        }
        return employeeList;
    }

    /**
     * 实现点赞
     * @param empId
     */
    @PreAuthorize("@ss.hasPermi('personnel:like:empId')")
    @GetMapping("/{empId}")
    public void isLike(@PathVariable("empId") int empId){
        likeService.isLike(empId);
    }


    /**
     * 获取排行榜信息
     * @return
     */
    @PreAuthorize("@ss.hasPermi('personnel:like:LikeList')")
    @GetMapping("/LikeList")
    public List<PhoneInfo> getLikeList(){
        return likeService.getLikeList();
    }

    /**
     * 获取动态点赞数据
     * @return
     */
    @PreAuthorize("@ss.hasPermi('personnel:like:DataLike')")
    @GetMapping("/DataLike")
    public List<DynamicInfo> getDataLike(){
        return likeService.getDataLike();
    }

    @PreAuthorize("@ss.hasPermi('personnel:like:mail')")
    @GetMapping("/mail")
    public String mail(EmailSong email){
        rabbitTemplate.convertAndSend(RabbitMQConfig.ITEM_TOPIC_EXCHANGE,"boot.ChengCheng",email);
        return "";
    }
}
